package com.htc.android.footprints.utils;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.location.Address;
import android.location.Location;
import android.net.Uri;
import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.widget.Toast;
import com.htc.android.footprints.commonui.ExportDialog;
import com.htc.android.footprints.kml.KMLUtil;
import com.htc.android.footprints.provider.FootprintManager;
import com.htc.android.footprints.utils.camera.FootprintImageManager;
import com.htc.android.footprints.utils.voice.FootprintVoiceManager;
import com.htc.android.footprints.vo.Footprint;
import com.htc.widget.HtcAlertDialog.Builder;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.SyncFailedException;
import java.math.BigInteger;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class FootprintUtils
{
  public static int CORRECT_FOOTPRINT = 0;
  public static int ERR_FOOTPRINT_ADDRESS = 0;
  public static int ERR_FOOTPRINT_NAME = 0;
  public static int ERR_FOOTPRINT_PHONE = 0;
  public static int ERR_FOOTPRINT_WEB = 0;
  private static final String LAT_LON_PATTERN = "{0}° {1}'' {2}\" {3}";
  private static final String SEC_PATTERN = "###.##";
  protected static final String TAG = "FootprintUtils";

  static
  {
    ERR_FOOTPRINT_ADDRESS = -4;
  }

  public static boolean CopyToNewExif(File paramFile1, File paramFile2)
  {
    int i;
    if (!paramFile1.exists())
      i = 0;
    while (true)
    {
      return i;
      if (!paramFile2.exists())
      {
        i = 0;
        continue;
      }
      HashMap localHashMap1 = new ExifInterface(paramFile2.getAbsolutePath()).getAttributes();
      ExifInterface localExifInterface = new ExifInterface(paramFile1.getAbsolutePath());
      HashMap localHashMap2 = localExifInterface.getAttributes();
      Iterator localIterator = localHashMap1.keySet().iterator();
      while (localIterator.hasNext())
      {
        String str = (String)localIterator.next();
        replaceExifTag(localHashMap2, str, (String)localHashMap1.get(str));
      }
      localExifInterface.saveAttributes(localHashMap2);
      localExifInterface.commitChanges();
      i = 1;
    }
  }

  public static Drawable boundCenterBottom(Drawable paramDrawable)
  {
    int i = paramDrawable.getIntrinsicWidth();
    int j = i / 2;
    int k = paramDrawable.getIntrinsicHeight();
    paramDrawable.setBounds(-j, 1 - k, i - j, 1);
    return paramDrawable;
  }

  public static boolean checkAudioData(Footprint paramFootprint)
  {
    int i;
    if (paramFootprint == null)
      i = 0;
    while (true)
    {
      return i;
      if (paramFootprint.mAudioPath == null)
      {
        i = 0;
        continue;
      }
      if (paramFootprint.mAudioPath.equalsIgnoreCase(""))
      {
        i = 0;
        continue;
      }
      if (!new File(paramFootprint.mAudioPath).exists())
      {
        i = 0;
        continue;
      }
      i = 1;
    }
  }

  public static boolean checkAudioData(String paramString)
  {
    int i;
    if (paramString == null)
      i = 0;
    while (true)
    {
      return i;
      if (paramString.equalsIgnoreCase(""))
      {
        i = 0;
        continue;
      }
      if (!new File(paramString).exists())
      {
        i = 0;
        continue;
      }
      i = 1;
    }
  }

  public static int checkFootprintLimitation(Footprint paramFootprint)
  {
    int i = CORRECT_FOOTPRINT;
    int j;
    if ((paramFootprint.mName == null) || (paramFootprint.mName.length() > 48))
      j = ERR_FOOTPRINT_NAME;
    while (true)
    {
      return j;
      if ((paramFootprint.mTel == null) || (paramFootprint.mTel.length() > 20))
      {
        j = ERR_FOOTPRINT_PHONE;
        continue;
      }
      if ((paramFootprint.mSite == null) || (paramFootprint.mSite.length() > 511))
      {
        j = ERR_FOOTPRINT_WEB;
        continue;
      }
      if ((paramFootprint.mAddr == null) || (paramFootprint.mAddr.length() > 511))
      {
        j = ERR_FOOTPRINT_ADDRESS;
        continue;
      }
      j = i;
    }
  }

  public static boolean checkPhotoData(String paramString)
  {
    int i;
    if (paramString == null)
      i = 0;
    while (true)
    {
      return i;
      if (paramString.equalsIgnoreCase(""))
      {
        i = 0;
        continue;
      }
      if (!new File(paramString).exists())
      {
        i = 0;
        continue;
      }
      i = 1;
    }
  }

  public static float convertRationalLatLonToDecimalString(String paramString)
  {
    try
    {
      String[] arrayOfString1 = paramString.split(",");
      String[] arrayOfString2 = arrayOfString1[0].split("/");
      int i = (int)(Float.parseFloat(arrayOfString2[0].trim()) / Float.parseFloat(arrayOfString2[1].trim()));
      String[] arrayOfString3 = arrayOfString1[1].split("/");
      int j = (int)(Float.parseFloat(arrayOfString3[0].trim()) / Float.parseFloat(arrayOfString3[1].trim()));
      String[] arrayOfString4 = arrayOfString1[2].split("/");
      float f2 = Float.parseFloat(arrayOfString4[0].trim());
      float f3 = Float.parseFloat(arrayOfString4[1].trim());
      float f4 = f2 / f3;
      f1 = i + j / 60.0F + f4 / 3600.0F;
      return f1;
    }
    catch (Exception localException)
    {
      while (true)
        float f1 = 0.0F;
    }
  }

  public static int convertRationalLatLonToInt(String paramString)
  {
    try
    {
      String[] arrayOfString1 = paramString.split(",");
      String[] arrayOfString2 = arrayOfString1[0].split("/");
      int j = (int)(Float.parseFloat(arrayOfString2[0].trim()) / Float.parseFloat(arrayOfString2[1].trim()));
      String[] arrayOfString3 = arrayOfString1[1].split("/");
      int k = (int)(Float.parseFloat(arrayOfString3[0].trim()) / Float.parseFloat(arrayOfString3[1].trim()));
      String[] arrayOfString4 = arrayOfString1[2].split("/");
      float f1 = Float.parseFloat(arrayOfString4[0].trim());
      float f2 = Float.parseFloat(arrayOfString4[1].trim());
      float f3 = f1 / f2;
      i = (int)(1000000.0D * (j + k / 60.0F + f3 / 3600.0F));
      return i;
    }
    catch (Exception localException)
    {
      while (true)
        int i = 0;
    }
  }

  public static int convertRationalLatLonToInt(String paramString1, String paramString2)
  {
    if ((paramString1 == null) || (paramString1.trim().equalsIgnoreCase("null")) || (paramString1.length() < 5));
    for (int i = 0; ; i = convertRationalLatLonToInt(paramString1))
    {
      if ((paramString2 != null) && (paramString2.trim().length() == 1) && ((paramString2.trim().equalsIgnoreCase("W")) || (paramString2.trim().equalsIgnoreCase("S")) || (i != 0)))
        i *= -1;
      return i;
    }
  }

  public static boolean copyFile(File paramFile1, File paramFile2)
  {
    int i;
    if ((paramFile1 == null) || (!paramFile1.exists()) || (paramFile2 == null))
      i = 0;
    FileChannel localFileChannel1;
    FileChannel localFileChannel2;
    while (true)
    {
      return i;
      localFileChannel1 = null;
      localFileChannel2 = null;
      try
      {
        localFileChannel1 = new FileInputStream(paramFile1).getChannel();
        FileOutputStream localFileOutputStream = new FileOutputStream(paramFile2);
        localFileChannel2 = localFileOutputStream.getChannel();
        localFileChannel2.transferFrom(localFileChannel1, 0L, localFileChannel1.size());
        localFileOutputStream.getFD().sync();
        if (localFileChannel1 != null);
        try
        {
          localFileChannel1.close();
          if (localFileChannel2 == null);
        }
        catch (IOException localIOException6)
        {
          try
          {
            localFileChannel2.close();
            i = 1;
            continue;
            localIOException6 = localIOException6;
            Log.w("FootprintUtils", localIOException6.getMessage(), localIOException6);
          }
          catch (IOException localIOException5)
          {
            while (true)
              Log.w("FootprintUtils", localIOException5.getMessage(), localIOException5);
          }
        }
      }
      catch (Exception localException)
      {
        while (true)
        {
          Log.e("FootprintUtils", localException.getMessage(), localException);
          if (localFileChannel1 != null);
          try
          {
            localFileChannel1.close();
            if (localFileChannel2 == null)
              continue;
          }
          catch (IOException localIOException4)
          {
            try
            {
              localFileChannel2.close();
              continue;
              localIOException4 = localIOException4;
              Log.w("FootprintUtils", localIOException4.getMessage(), localIOException4);
            }
            catch (IOException localIOException3)
            {
              while (true)
                Log.w("FootprintUtils", localIOException3.getMessage(), localIOException3);
            }
          }
        }
      }
      finally
      {
        if (localFileChannel1 == null);
      }
    }
    try
    {
      localFileChannel1.close();
      if (localFileChannel2 == null);
    }
    catch (IOException localIOException2)
    {
      try
      {
        localFileChannel2.close();
        throw localObject;
        localIOException2 = localIOException2;
        Log.w("FootprintUtils", localIOException2.getMessage(), localIOException2);
      }
      catch (IOException localIOException1)
      {
        while (true)
          Log.w("FootprintUtils", localIOException1.getMessage(), localIOException1);
      }
    }
  }

  public static String defaultStr(String paramString1, String paramString2)
  {
    if (paramString1 == null);
    for (String str = paramString2; ; str = paramString1)
      return str;
  }

  public static void deleteFootprint(Context paramContext, Footprint paramFootprint)
  {
    if (checkAudioData(paramFootprint.mAudioPath))
      new File(paramFootprint.mAudioPath).delete();
    if (checkPhotoData(paramFootprint.mPicPath))
      new File(paramFootprint.mPicPath).delete();
    FootprintManager.getInstance(paramContext).removeFootprint(paramFootprint);
  }

  public static void deleteFootprint(Context paramContext, Footprint[] paramArrayOfFootprint)
  {
    int i = paramArrayOfFootprint.length;
    for (int j = 0; j < i; j++)
      deleteFootprint(paramContext, paramArrayOfFootprint[j]);
  }

  public static void exportKMZ(Activity paramActivity, String paramString, Footprint[] paramArrayOfFootprint)
  {
    if (FootprintImageManager.hasStorage(true))
    {
      ExportDialog localExportDialog = new ExportDialog(paramActivity);
      localExportDialog.show();
      new Thread(paramString, paramActivity, localExportDialog, paramArrayOfFootprint)
      {
        public void run()
        {
          try
          {
            String str = KMLUtil.getOuputFile(FootprintUtils.this + "_" + FootprintUtils.getDateWithSerialNo(this.val$activity.getApplicationContext()));
            File localFile1 = new File(str);
            if (!localFile1.getParentFile().exists())
              localFile1.getParentFile().mkdir();
            File localFile2 = File.createTempFile(".temp", ".kmz", localFile1.getParentFile());
            FileOutputStream localFileOutputStream = new FileOutputStream(localFile2);
            KMLUtil.setProgressListener(this.val$dialog);
            KMLUtil.exportKMZ(this.val$footprints, localFileOutputStream);
            localFileOutputStream.flush();
            localFileOutputStream.close();
            FootprintUtils.copyFile(localFile2, localFile1);
            localFile2.delete();
            this.val$dialog.dismiss();
            this.val$activity.runOnUiThread(new Runnable(str)
            {
              public void run()
              {
                HtcAlertDialog.Builder localBuilder = new HtcAlertDialog.Builder(FootprintUtils.1.this.val$activity).setIcon(2130837677).setTitle(FootprintUtils.1.this.val$activity.getResources().getString(2131361960));
                Activity localActivity = FootprintUtils.1.this.val$activity;
                Object[] arrayOfObject = new Object[1];
                arrayOfObject[0] = this.val$FILE_NAME.replace("/sdcard/", "");
                localBuilder.setMessage(localActivity.getString(2131361902, arrayOfObject)).setNeutralButton(2131361893, null).show();
              }
            });
            return;
          }
          catch (FileNotFoundException localFileNotFoundException)
          {
            while (true)
              Log.e("FootprintUtils", localFileNotFoundException.getMessage(), localFileNotFoundException);
          }
          catch (IOException localIOException)
          {
            while (true)
              Log.e("FootprintUtils", localIOException.getMessage(), localIOException);
          }
        }
      }
      .start();
    }
  }

  public static void forceSync(ContentResolver paramContentResolver, String paramString)
  {
    new Thread(new Runnable(paramString, paramContentResolver)
    {
      public void run()
      {
        try
        {
          Uri localUri = Uri.parse("file://" + FootprintImageManager.getDirectory() + File.separator + FootprintUtils.this);
          ParcelFileDescriptor localParcelFileDescriptor = this.val$cr.openFileDescriptor(localUri, "r");
          localParcelFileDescriptor.getFileDescriptor().sync();
          localParcelFileDescriptor.close();
          return;
        }
        catch (FileNotFoundException localFileNotFoundException)
        {
          while (true)
            Log.e("FootprintUtils", "forceSync FileNotFoundException " + localFileNotFoundException);
        }
        catch (SyncFailedException localSyncFailedException)
        {
          while (true)
            Log.e("FootprintUtils", "forceSync SyncFailedException " + localSyncFailedException);
        }
        catch (IOException localIOException)
        {
          while (true)
            Log.e("FootprintUtils", "forceSync IOException " + localIOException);
        }
      }
    }).start();
  }

  public static String generateMD5(String paramString)
  {
    try
    {
      String str;
      for (Object localObject2 = new BigInteger(1, MessageDigest.getInstance("MD5").digest(paramString.getBytes())).toString(16); ((String)localObject2).length() < 32; localObject2 = str)
        str = "0" + (String)localObject2;
      localObject1 = localObject2;
      return localObject1;
    }
    catch (NoSuchAlgorithmException localNoSuchAlgorithmException)
    {
      while (true)
      {
        Log.e("MD5", localNoSuchAlgorithmException.getMessage());
        Object localObject1 = null;
      }
    }
  }

  public static String getAddressByLocale(Address paramAddress, Context paramContext)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    String str1 = defaultStr(paramAddress.getCountryCode(), "");
    String str2 = defaultStr(paramAddress.getCountryName(), "");
    String str3 = defaultStr(paramAddress.getAdminArea(), "");
    String str4 = defaultStr(paramAddress.getSubAdminArea(), "");
    String str5 = defaultStr(paramAddress.getLocality(), "");
    String str6 = defaultStr(paramAddress.getThoroughfare(), "");
    localStringBuilder.append(str1);
    localStringBuilder.append(str2);
    localStringBuilder.append(str3);
    localStringBuilder.append(str4);
    localStringBuilder.append(str5);
    localStringBuilder.append(str6);
    return localStringBuilder.toString();
  }

  public static int getBrightPreferences(Context paramContext)
  {
    return paramContext.getSharedPreferences("Footprints", 0).getInt("FOOTPRINTS_CAMERA_BRIGHT", 5);
  }

  public static Drawable getCategoryIcon(Context paramContext, String paramString)
  {
    Resources localResources = paramContext.getResources();
    Drawable localDrawable;
    if (paramString.equalsIgnoreCase("favorite"))
      localDrawable = localResources.getDrawable(2130837702);
    while (true)
    {
      return localDrawable;
      if (paramString.equalsIgnoreCase("shopping"))
      {
        localDrawable = localResources.getDrawable(2130837739);
        continue;
      }
      if (paramString.equalsIgnoreCase("dining"))
      {
        localDrawable = localResources.getDrawable(2130837737);
        continue;
      }
      if (paramString.equalsIgnoreCase("leisure"))
      {
        localDrawable = localResources.getDrawable(2130837726);
        continue;
      }
      if (paramString.equalsIgnoreCase("other"))
      {
        localDrawable = localResources.getDrawable(2130837736);
        continue;
      }
      localDrawable = localResources.getDrawable(2130837505);
    }
  }

  public static Drawable getCategoryOverlayIcon(Context paramContext, String paramString)
  {
    Resources localResources = paramContext.getResources();
    Drawable localDrawable;
    if (paramString.equalsIgnoreCase("favorite"))
      localDrawable = localResources.getDrawable(2130837753);
    while (true)
    {
      return localDrawable;
      if (paramString.equalsIgnoreCase("shopping"))
      {
        localDrawable = localResources.getDrawable(2130837757);
        continue;
      }
      if (paramString.equalsIgnoreCase("dining"))
      {
        localDrawable = localResources.getDrawable(2130837756);
        continue;
      }
      if (paramString.equalsIgnoreCase("leisure"))
      {
        localDrawable = localResources.getDrawable(2130837754);
        continue;
      }
      if (paramString.equalsIgnoreCase("other"))
      {
        localDrawable = localResources.getDrawable(2130837755);
        continue;
      }
      localDrawable = localResources.getDrawable(2130837752);
    }
  }

  public static String getDBPathOnSD()
  {
    return StorageUtil.getFootprintStorageDirectory() + File.separator + "footprints.db";
  }

  public static String getDateWithSerialNo(Context paramContext)
  {
    DecimalFormat localDecimalFormat = new DecimalFormat("000");
    SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("Footprints", 0);
    SharedPreferences.Editor localEditor = localSharedPreferences.edit();
    localSharedPreferences.getString("DATE", "");
    int i = 1 + localSharedPreferences.getInt("SERIAL", 0);
    String str = localDecimalFormat.format(i);
    localEditor.putInt("SERIAL", i);
    localEditor.commit();
    return str;
  }

  public static String getDefaultName(Context paramContext)
  {
    DecimalFormat localDecimalFormat = new DecimalFormat(" ##000");
    int i = SettingInfo.getInstance(paramContext).getNewSerialNumber();
    return "Footprints " + localDecimalFormat.format(i);
  }

  public static int getExtDBVersion()
  {
    int i = -1;
    File localFile = new File(getDBPathOnSD());
    SQLiteDatabase localSQLiteDatabase;
    if ((localFile != null) && (localFile.exists()) && (localFile.length() > 0L))
      localSQLiteDatabase = null;
    try
    {
      localSQLiteDatabase = SQLiteDatabase.openDatabase(getDBPathOnSD(), null, 1);
      int j = localSQLiteDatabase.getVersion();
      i = j;
      return i;
    }
    catch (SQLiteException localSQLiteException)
    {
      while (true)
      {
        localSQLiteException.printStackTrace();
        localSQLiteDatabase.close();
      }
    }
    finally
    {
      localSQLiteDatabase.close();
    }
    throw localObject;
  }

  public static String getFormatedLat(int paramInt)
  {
    String[] arrayOfString1 = Location.convert(paramInt / 1000000.0D, 2).split(":");
    new DecimalFormat("###.##");
    MessageFormat localMessageFormat = new MessageFormat("{0}° {1}'' {2}\" {3}");
    String[] arrayOfString2 = new String[4];
    arrayOfString2[0] = String.valueOf(Math.abs(Integer.parseInt(arrayOfString1[0])));
    arrayOfString2[1] = arrayOfString1[1];
    String[] arrayOfString3 = arrayOfString1[2].split("\\.");
    String str1 = new String("0");
    if (arrayOfString3.length >= 2)
    {
      if (arrayOfString3[1].length() > 2)
        str1 = arrayOfString3[1].substring(0, 2);
    }
    else
    {
      arrayOfString2[2] = (arrayOfString3[0] + "." + str1);
      if (Integer.parseInt(arrayOfString1[0]) < 0)
        break label186;
    }
    label186: for (String str2 = "N"; ; str2 = "S")
    {
      arrayOfString2[3] = str2;
      return localMessageFormat.format(arrayOfString2);
      str1 = arrayOfString3[1];
      break;
    }
  }

  public static String getFormatedLon(int paramInt)
  {
    double d = paramInt / 1000000.0D;
    new DecimalFormat("###.##");
    MessageFormat localMessageFormat = new MessageFormat("{0}° {1}'' {2}\" {3}");
    String[] arrayOfString1 = Location.convert(d, 2).split(":");
    String[] arrayOfString2 = new String[4];
    arrayOfString2[0] = String.valueOf(Math.abs(Integer.parseInt(arrayOfString1[0])));
    arrayOfString2[1] = arrayOfString1[1];
    String[] arrayOfString3 = arrayOfString1[2].split("\\.");
    String str1 = new String("0");
    if (arrayOfString3.length >= 2)
    {
      if (arrayOfString3[1].length() > 2)
        str1 = arrayOfString3[1].substring(0, 2);
    }
    else
    {
      arrayOfString2[2] = (arrayOfString3[0] + "." + str1);
      if (Integer.parseInt(arrayOfString1[0]) < 0)
        break label195;
    }
    label195: for (String str2 = "E"; ; str2 = "W")
    {
      arrayOfString2[3] = str2;
      return localMessageFormat.format(arrayOfString2);
      str1 = arrayOfString3[1];
      break;
    }
  }

  public static Drawable getInverse(Drawable paramDrawable)
  {
    Bitmap localBitmap = Bitmap.createBitmap(paramDrawable.getIntrinsicWidth(), paramDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas localCanvas = new Canvas(localBitmap);
    paramDrawable.setColorFilter(-1118482, PorterDuff.Mode.SRC_IN);
    paramDrawable.draw(localCanvas);
    paramDrawable.clearColorFilter();
    return new BitmapDrawable(localBitmap);
  }

  public static Drawable getInverseCategory(Context paramContext, String paramString)
  {
    Resources localResources = paramContext.getResources();
    Drawable localDrawable;
    if (paramString.equalsIgnoreCase("favorite"))
      localDrawable = localResources.getDrawable(2130837636);
    while (true)
    {
      return localDrawable;
      if (paramString.equalsIgnoreCase("shopping"))
      {
        localDrawable = localResources.getDrawable(2130837769);
        continue;
      }
      if (paramString.equalsIgnoreCase("dining"))
      {
        localDrawable = localResources.getDrawable(2130837765);
        continue;
      }
      if (paramString.equalsIgnoreCase("leisure"))
      {
        localDrawable = localResources.getDrawable(2130837742);
        continue;
      }
      if (paramString.equalsIgnoreCase("other"))
      {
        localDrawable = localResources.getDrawable(2130837750);
        continue;
      }
      localDrawable = localResources.getDrawable(2130837504);
    }
  }

  public static Location getLocationFromPicture(Context paramContext, String paramString)
  {
    HashMap localHashMap = new ExifInterface(paramString).getAttributes();
    String str1 = (String)localHashMap.get("GPSLatitude");
    String str2 = (String)localHashMap.get("GPSLongitude");
    String str3 = (String)localHashMap.get("GPSLatitudeRef");
    String str4 = (String)localHashMap.get("GPSLongitudeRef");
    Log.d("FootprintUtils", "read picture lat = " + str1 + "/ lat ref = " + str3);
    Log.d("FootprintUtils", "read picture lon = " + str2 + "/ lon ref = " + str4);
    String str5 = ExifInterface.convertRationalLatLonToDecimalString(str1, "lat", false);
    String str6 = ExifInterface.convertRationalLatLonToDecimalString(str2, "lon", false);
    Log.d("FootprintUtils", "read picture lat = " + str5);
    Log.d("FootprintUtils", "read picture lon = " + str6);
    Location localLocation = new Location("gps");
    localLocation.setLatitude(0.0D);
    localLocation.setLongitude(0.0D);
    return localLocation;
  }

  public static int[] getLocationFromPicture(String paramString)
  {
    int[] arrayOfInt = new int[2];
    HashMap localHashMap = new ExifInterface(paramString).getAttributes();
    String str1 = (String)localHashMap.get("GPSLatitude");
    String str2 = (String)localHashMap.get("GPSLongitude");
    arrayOfInt[0] = (int)(1000000.0F * convertRationalLatLonToDecimalString(str1));
    arrayOfInt[1] = (int)(1000000.0F * convertRationalLatLonToDecimalString(str2));
    Log.d("FootprintUtils", "read picture lat = " + str1);
    Log.d("FootprintUtils", "read picture lon = " + str2);
    return arrayOfInt;
  }

  public static Intent getResetIntent()
  {
    Intent localIntent = new Intent();
    localIntent.setAction("com.htc.android.footprints.ListModeActivity");
    localIntent.setFlags(67108864);
    localIntent.putExtra("reset", true);
    return localIntent;
  }

  public static int getSizeOfDB(Context paramContext)
  {
    return FootprintManager.getInstance(paramContext).getFootprintAll(null).size();
  }

  public static Drawable getTabCategoryIcon(Context paramContext, String paramString)
  {
    Resources localResources = paramContext.getResources();
    Drawable localDrawable;
    if (paramString.equalsIgnoreCase("favorite"))
      localDrawable = localResources.getDrawable(2130837637);
    while (true)
    {
      return localDrawable;
      if (paramString.equalsIgnoreCase("shopping"))
      {
        localDrawable = localResources.getDrawable(2130837770);
        continue;
      }
      if (paramString.equalsIgnoreCase("dining"))
      {
        localDrawable = localResources.getDrawable(2130837766);
        continue;
      }
      if (paramString.equalsIgnoreCase("leisure"))
      {
        localDrawable = localResources.getDrawable(2130837743);
        continue;
      }
      if (paramString.equalsIgnoreCase("other"))
      {
        localDrawable = localResources.getDrawable(2130837751);
        continue;
      }
      localDrawable = localResources.getDrawable(2130837505);
    }
  }

  public static int getWBPreferences(Context paramContext)
  {
    int i = paramContext.getSharedPreferences("Footprints", 0).getInt("FOOTPRINTS_CAMERA_WB", 0);
    if (i < 0)
    {
      putWBPreferences(paramContext, 0);
      i = 0;
    }
    return i;
  }

  public static boolean importJPG(Context paramContext, File paramFile, Bitmap paramBitmap, String paramString)
  {
    if ((paramFile == null) || (paramBitmap == null));
    for (int i = 0; ; i = 0)
    {
      return i;
      if (FootprintImageManager.hasStorage(true))
        break;
    }
    String str1 = String.valueOf(System.currentTimeMillis());
    String str2 = str1 + ".jpg";
    String str3 = FootprintImageManager.getDirectory() + File.separator + str2;
    FootprintImageManager.getInstance().forceWriteToFile(paramContext.getContentResolver(), paramBitmap, str2);
    new File(str3);
    int[] arrayOfInt = getLocationFromPicture(paramFile.getAbsolutePath());
    Footprint localFootprint = new Footprint();
    localFootprint.mName = str1;
    localFootprint.mCreateTime = Long.valueOf(str1).longValue();
    localFootprint.mPicFileName = str2;
    localFootprint.mPicPath = str3;
    if ((paramString != null) && (paramString.length() > 0));
    for (String str4 = paramString; ; str4 = "favorite")
    {
      localFootprint.mCategory = str4;
      localFootprint.mLatitude = arrayOfInt[0];
      localFootprint.mLongitude = arrayOfInt[1];
      localFootprint.setAudio(null);
      FootprintManager.getInstance(paramContext).addFootprint(localFootprint);
      setLocationToPicture(localFootprint);
      i = 1;
      break;
    }
  }

  public static boolean isOnBackground(Context paramContext)
  {
    int i = 0;
    Iterator localIterator = ((ActivityManager)paramContext.getSystemService("activity")).getRunningAppProcesses().iterator();
    while (localIterator.hasNext())
    {
      ActivityManager.RunningAppProcessInfo localRunningAppProcessInfo = (ActivityManager.RunningAppProcessInfo)localIterator.next();
      String str = localRunningAppProcessInfo.processName;
      int j = localRunningAppProcessInfo.importance;
      Log.d("FootprintUtils", "name/importance/lru = " + str + " / " + j + " / " + localRunningAppProcessInfo.lru);
      if (!str.equals("com.htc.android.footprints"))
        continue;
      Log.d("FootprintUtils", "app = footprint");
      Log.d("FootprintUtils", "app name / importance = " + str + " / " + j);
      if (400 != j)
        continue;
      i = 1;
      Log.d("FootprintUtils", str + ": background" + ", " + localRunningAppProcessInfo.lru);
    }
    return i;
  }

  public static boolean isResetByWidget()
  {
    String str = FootprintImageManager.getFootprintsDirectory();
    File localFile = new File(str + File.separator + "fpwidget.txt");
    boolean bool = localFile.exists();
    if (bool)
      new Handler().postDelayed(new Runnable(localFile)
      {
        public void run()
        {
          FootprintUtils.this.delete();
        }
      }
      , 500L);
    Log.d("FootprintUtils", "isResetByWidget = " + bool);
    return bool;
  }

  public static boolean isStorageEnough(Context paramContext)
  {
    if ((StorageUtil.isExternalStorageEnough()) && (StorageUtil.isInternalStorageEnough()));
    for (int i = 1; ; i = 0)
    {
      return i;
      ((Activity)paramContext).runOnUiThread(new Runnable(paramContext)
      {
        public void run()
        {
          Toast.makeText(FootprintUtils.this, 2131361887, 1).show();
        }
      });
    }
  }

  public static boolean isStorageEnough(Context paramContext, long paramLong)
  {
    if (StorageUtil.isExternalStorageEnough(2097152L + paramLong));
    for (int i = 1; ; i = 0)
    {
      return i;
      ((Activity)paramContext).runOnUiThread(new Runnable(paramContext)
      {
        public void run()
        {
          Toast.makeText(FootprintUtils.this, 2131361887, 1).show();
        }
      });
    }
  }

  public static void processPreset(Context paramContext)
  {
    SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("Footprints", 0);
    boolean bool = localSharedPreferences.getBoolean("PRESET", false);
    FootprintManager localFootprintManager = FootprintManager.getInstance(paramContext);
    InputStream localInputStream;
    if (!bool)
    {
      SharedPreferences.Editor localEditor = localSharedPreferences.edit();
      localEditor.putBoolean("PRESET", true);
      localEditor.commit();
      Log.d("FootprintUtils", "install preset Footprints");
      touchSDFile();
      localInputStream = null;
    }
    try
    {
      localInputStream = paramContext.getAssets().open("preset.kmz");
      localFootprintManager.addNonDuplicatedFootprint(KMLUtil.importKMZ(localInputStream));
      if (localInputStream != null);
      try
      {
        localInputStream.close();
        return;
      }
      catch (IOException localIOException4)
      {
        while (true)
          Log.w("FootprintUtils", localIOException4.getMessage(), localIOException4);
      }
    }
    catch (IOException localIOException2)
    {
      while (true)
      {
        Log.e("FootprintUtils", localIOException2.getMessage(), localIOException2);
        if (localInputStream == null)
          continue;
        try
        {
          localInputStream.close();
        }
        catch (IOException localIOException3)
        {
          Log.w("FootprintUtils", localIOException3.getMessage(), localIOException3);
        }
      }
    }
    finally
    {
      if (localInputStream == null);
    }
    try
    {
      localInputStream.close();
      throw localObject;
    }
    catch (IOException localIOException1)
    {
      while (true)
        Log.w("FootprintUtils", localIOException1.getMessage(), localIOException1);
    }
  }

  public static void processPresetDate(Context paramContext)
  {
    Log.d("FootprintUtils", "preset data");
    touchSDFile();
    SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("Footprints", 0);
    boolean bool = localSharedPreferences.getBoolean("PRESET", false);
    FootprintManager localFootprintManager = FootprintManager.getInstance(paramContext);
    File localFile = new File(StorageUtil.getFootprintStorageDirectory() + File.separator + "footprints.db");
    if ((localFile.exists()) && (copyFile(localFile, paramContext.getDatabasePath("footprints.db"))))
    {
      SharedPreferences.Editor localEditor2 = localSharedPreferences.edit();
      localEditor2.putBoolean("PRESET", true);
      localEditor2.commit();
    }
    InputStream localInputStream1;
    if (!bool)
    {
      Log.d("FootprintUtils", "install preset Footprints");
      localInputStream1 = null;
    }
    try
    {
      localInputStream1 = paramContext.getAssets().open("preset.kmz");
      localFootprintManager.addFootprint(KMLUtil.importKMZ(localInputStream1));
      if (localInputStream1 != null)
        try
        {
          localInputStream1.close();
          SharedPreferences.Editor localEditor1 = localSharedPreferences.edit();
          localEditor1.putBoolean("PRESET", true);
          localEditor1.commit();
          return;
        }
        catch (IOException localIOException4)
        {
          while (true)
            Log.w("FootprintUtils", localIOException4.getMessage(), localIOException4);
        }
    }
    catch (IOException localIOException2)
    {
      while (true)
      {
        Log.e("FootprintUtils", localIOException2.getMessage(), localIOException2);
        if (localInputStream1 == null)
          break;
        try
        {
          localInputStream1.close();
        }
        catch (IOException localIOException3)
        {
          Log.w("FootprintUtils", localIOException3.getMessage(), localIOException3);
        }
      }
    }
    finally
    {
      while (true)
      {
        InputStream localInputStream2 = localInputStream1;
        if (localInputStream2 != null);
        try
        {
          localInputStream2.close();
          throw localObject;
        }
        catch (IOException localIOException1)
        {
          while (true)
            Log.w("FootprintUtils", localIOException1.getMessage(), localIOException1);
        }
      }
    }
  }

  public static void putBrightPreferences(Context paramContext, int paramInt)
  {
    SharedPreferences.Editor localEditor = paramContext.getSharedPreferences("Footprints", 0).edit();
    localEditor.putInt("FOOTPRINTS_CAMERA_BRIGHT", paramInt);
    localEditor.commit();
  }

  public static void putWBPreferences(Context paramContext, int paramInt)
  {
    SharedPreferences.Editor localEditor = paramContext.getSharedPreferences("Footprints", 0).edit();
    localEditor.putInt("FOOTPRINTS_CAMERA_WB", paramInt);
    localEditor.commit();
  }

  private static void replaceExifTag(HashMap<String, String> paramHashMap, String paramString1, String paramString2)
  {
    if (paramHashMap == null);
    while (true)
    {
      return;
      if (!paramHashMap.containsKey(paramString1))
        paramHashMap.remove(paramString1);
      paramHashMap.put(paramString1, paramString2);
    }
  }

  public static void saveAsContacts(Context paramContext, Footprint paramFootprint)
  {
    Intent localIntent = new Intent();
    localIntent.addFlags(268435456);
    localIntent.setAction("android.intent.action.INSERT");
    localIntent.setData(Uri.parse("content://contacts/people"));
    localIntent.putExtra("ConImage", FootprintImageManager.getInstance().getScaledImage(new File(paramFootprint.mPicPath), paramContext, 50, 50, false));
    localIntent.putExtra("name", paramFootprint.mName);
    String str1;
    String str2;
    if ((paramFootprint.mComment != null) && (paramFootprint.mComment.length() > 0))
    {
      str1 = paramFootprint.mComment;
      localIntent.putExtra("notes", str1);
      if ((paramFootprint.mAddr == null) || (paramFootprint.mAddr.length() <= 0))
        break label190;
      str2 = paramFootprint.mAddr;
      label134: localIntent.putExtra("postal", str2);
      if ((paramFootprint.mTel == null) || (paramFootprint.mTel.length() <= 0))
        break label197;
    }
    label190: label197: for (String str3 = paramFootprint.mTel; ; str3 = "")
    {
      localIntent.putExtra("phone", str3);
      paramContext.startActivity(localIntent);
      return;
      str1 = "";
      break;
      str2 = "";
      break label134;
    }
  }

  public static void saveFootprintIndex(int paramInt)
  {
    String str1 = FootprintImageManager.getFootprintsDirectory();
    String str2 = str1 + File.separator + "index.txt";
    String str3 = "index=" + String.valueOf(paramInt);
    try
    {
      FileOutputStream localFileOutputStream = new FileOutputStream(str2);
      try
      {
        localFileOutputStream.write(str3.getBytes(), 0, str3.length());
        localFileOutputStream.flush();
        localFileOutputStream.getFD().sync();
        localFileOutputStream.close();
        Log.d("FootprintUtils", "saveFootprintIndex");
        return;
      }
      catch (IOException localIOException)
      {
        while (true)
          localIOException.printStackTrace();
      }
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      while (true)
        localFileNotFoundException.printStackTrace();
    }
  }

  public static void setCameraBrightness(Camera paramCamera, int paramInt)
  {
    if (paramCamera != null)
    {
      Camera.Parameters localParameters = paramCamera.getParameters();
      localParameters.set("brightness", String.valueOf(paramInt));
      paramCamera.setParameters(localParameters);
    }
  }

  public static void setCameraWhiteBalance(Camera paramCamera, String paramString)
  {
    if (paramCamera != null)
    {
      Camera.Parameters localParameters = paramCamera.getParameters();
      localParameters.set("whitebalance", paramString);
      paramCamera.setParameters(localParameters);
    }
  }

  public static void setLocationToPicture(Footprint paramFootprint)
  {
    if (paramFootprint == null);
    while (true)
    {
      return;
      Log.d("FootprintUtils", "setLocationToPicture");
      HashMap localHashMap = null;
      ExifInterface localExifInterface = new ExifInterface(paramFootprint.mPicPath);
      if (localHashMap == null)
        localHashMap = localExifInterface.getAttributes();
      double d1 = paramFootprint.mLatitude / 1000000.0D;
      double d2 = paramFootprint.mLongitude / 1000000.0D;
      String str1 = ExifInterface.makeLatLongString(d1);
      String str2 = ExifInterface.makeLatLongString(d2);
      replaceExifTag(localHashMap, "GPSLatitude", str1);
      replaceExifTag(localHashMap, "GPSLongitude", str2);
      replaceExifTag(localHashMap, "GPSLatitudeRef", ExifInterface.makeLatStringRef(d1));
      replaceExifTag(localHashMap, "GPSLongitudeRef", ExifInterface.makeLatStringRef(d2));
      Log.i("FootprintUtils", "lat = " + str1);
      Log.i("FootprintUtils", "lon = " + str2);
      localExifInterface.saveAttributes(localHashMap);
      localExifInterface.commitChanges();
    }
  }

  public static void setLocationToPicture(File paramFile, String[] paramArrayOfString)
  {
    if ((paramArrayOfString.length == 0) || (paramFile == null));
    while (true)
    {
      return;
      Log.d("FootprintUtils", "setLocationToPicture");
      HashMap localHashMap = null;
      ExifInterface localExifInterface = new ExifInterface(paramFile.getAbsolutePath());
      if (localHashMap == null)
        localHashMap = localExifInterface.getAttributes();
      replaceExifTag(localHashMap, "GPSLatitude", paramArrayOfString[0]);
      replaceExifTag(localHashMap, "GPSLongitude", paramArrayOfString[1]);
      Log.i("FootprintUtils", "lat = " + paramArrayOfString[0]);
      Log.i("FootprintUtils", "lon = " + paramArrayOfString[1]);
      localExifInterface.saveAttributes(localHashMap);
      localExifInterface.commitChanges();
    }
  }

  public static void setWidgetFlag()
  {
    String str1 = FootprintImageManager.getFootprintsDirectory();
    String str2 = str1 + File.separator + "fpwidget.txt";
    try
    {
      FileOutputStream localFileOutputStream = new FileOutputStream(str2);
      try
      {
        localFileOutputStream.write("widget flag".getBytes(), 0, "widget flag".length());
        localFileOutputStream.flush();
        localFileOutputStream.getFD().sync();
        localFileOutputStream.close();
        Log.d("FootprintUtils", "setWidgetFlag");
        return;
      }
      catch (IOException localIOException)
      {
        while (true)
          localIOException.printStackTrace();
      }
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      while (true)
        localFileNotFoundException.printStackTrace();
    }
  }

  public static void showFootprint(Footprint paramFootprint)
  {
    Log.d("FootprintUtils", "--------------------------------------");
    Log.d("FootprintUtils", "Footprint Name:" + paramFootprint.mName);
    Log.d("FootprintUtils", "Footprint accuracy:" + paramFootprint.mAccuracy);
    Log.d("FootprintUtils", "Footprint addr:" + paramFootprint.mAddr);
    Log.d("FootprintUtils", "Footprint audio name:" + paramFootprint.mAudioFileName);
    Log.d("FootprintUtils", "Footprint auido path:" + paramFootprint.mAudioPath);
    Log.d("FootprintUtils", "Footprint category:" + paramFootprint.mCategory);
    Log.d("FootprintUtils", "Footprint comment:" + paramFootprint.mComment);
    Log.d("FootprintUtils", "Footprint create time:" + paramFootprint.mCreateTime);
    Log.d("FootprintUtils", "Footprint drawable id:" + paramFootprint.mDrewableID);
    Log.d("FootprintUtils", "Footprint latitude:" + paramFootprint.mLatitude);
    Log.d("FootprintUtils", "Footprint longtidue:" + paramFootprint.mLongitude);
    Log.d("FootprintUtils", "Footprint photo name:" + paramFootprint.mPicFileName);
    Log.d("FootprintUtils", "Footprint photo path:" + paramFootprint.mPicPath);
    Log.d("FootprintUtils", "Footprint Rate:" + paramFootprint.mRate);
    Log.d("FootprintUtils", "Footprint Stie:" + paramFootprint.mSite);
    Log.d("FootprintUtils", "Footprint Tel:" + paramFootprint.mTel);
    Log.d("FootprintUtils", "Footprint Version:" + paramFootprint.mVersion);
    Log.d("FootprintUtils", "--------------------------------------");
  }

  public static void showToast(Context paramContext, int paramInt)
  {
    if ((paramInt != 0) && (paramContext != null))
      Toast.makeText(paramContext, paramInt, 1).show();
  }

  public static void showToast(Context paramContext, String paramString)
  {
    if ((paramString != null) && (paramContext != null))
      Toast.makeText(paramContext, paramString, 1).show();
  }

  public static void touchSDFile()
  {
    File[] arrayOfFile = new File[3];
    arrayOfFile[0] = new File(StorageUtil.getFootprintStorageDirectory());
    arrayOfFile[1] = new File(FootprintImageManager.getDirectory());
    arrayOfFile[2] = new File(FootprintVoiceManager.getDirectory());
    int i = arrayOfFile.length;
    for (int j = 0; j < i; j++)
    {
      File localFile = arrayOfFile[j];
      if (localFile.exists())
        continue;
      localFile.mkdir();
    }
  }
}

/* Location:           E:\workspace\dex2java\dex-translator-0.0.9.3\HtcFootprints_dex2jar.jar
 * Qualified Name:     com.htc.android.footprints.utils.FootprintUtils
 * JD-Core Version:    0.6.0
 */